<template>
  <div>
    <p>数组里所有学生的年龄和:</p>
    <span>{{ totalAge }}岁</span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [
        {
          name: "小明",
          age: 18,
        },
        {
          name: "小花",
          age: 25,
        },
        {
          name: "小爱",
          age: 21,
        },
      ],
    };
  },
  computed:{
      totalAge(){
        return  this.arr.reduce((accu,val)=>{
              return accu+=val.age
          },0)
      }
  }
};
</script>

<style>
</style>